/**
 * 
 */
package bplusfile;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

/**
 * @author ernesto
 *
 */
public class BPlusTreeFile extends RandomAccessFile {
	private char separatorAttribute;
	private char separatorField;
	
	
	/**
	 * @param arg0
	 * @param arg1
	 * @throws FileNotFoundException
	 */
	public BPlusTreeFile(String arg0, String arg1) throws FileNotFoundException {
		super(arg0, arg1);
	}

	/**
	 * @param arg0
	 * @param arg1
	 * @throws FileNotFoundException
	 */
	public BPlusTreeFile(File arg0, String arg1) throws FileNotFoundException {
		super(arg0, arg1);

	}
	
	public BPlusTreeFile(String arg0, String arg1,char i, char j) throws FileNotFoundException {
		super(arg0, arg1);
		setSeparatorAttribute(i);
		setSeparatorField(j);
	}
	
	

	/**
	 * @return the separatorAttribute
	 */
	public char getSeparatorAttribute() {
		return separatorAttribute;
	}

	/**
	 * @param separatorAttribute the separatorAttribute to set
	 */
	public void setSeparatorAttribute(char separatorAttribute) {
		this.separatorAttribute = separatorAttribute;
	}

	/**
	 * @return the separatorField
	 */
	public char getSeparatorField() {
		return separatorField;
	}

	/**
	 * @param separatorField the separatorField to set
	 */
	public void setSeparatorField(char separatorField) {
		this.separatorField = separatorField;
	}
	
	/**
	 * Reads the string until the next ocurrence of separator.
	 * @return
	 * @throws IOException 
	 */
	public String readUntil(char separator) throws IOException{
		//System.out.println(getFilePointer());
		//seek(getFilePointer()-32);
		char aux=(char)read();
		String out="";
		//System.out.println("entra");
		//System.out.println(separator);
		//int i=0;
		while(aux!=separator){//aux!=separator
			//i++;
			//System.out.println(getFilePointer());
			//System.out.println(out);
			out=out+aux;
			aux=(char)read();
		}
		//System.out.println(out);
		//System.out.println("sale");
		return out;
	}
	
	/**
	 * Reads the string until the next fieldSeparator
	 * @return
	 * @throws IOException
	 */
	
	public String readField() throws IOException{
		return readUntil(getSeparatorField());
	}
	
	
	
	

}
